package com.happyscan138.makefun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.happyscan138.makefun.BaseAdapter.myself;
import com.happyscan138.makefun.R;

import java.util.List;

/**
 * Created by Administrator on 2016/11/29.
 */

public class myselfAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater mInflater;//动态布局映射
    private List<myself> data;


    public myselfAdapter(Context context, List<myself> data ) {
        this.context = context;
        this.data = data;

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {

        ViewHolder viewHolder=new ViewHolder();
        //判断converView是否为空
        if(converView==null){
            viewHolder=new ViewHolder();
            converView=View.inflate(context, R.layout.myself_item,null);
            viewHolder.myself_head=(ImageView)converView.findViewById(R.id.myself_item_icon);
            viewHolder.myself_text=(TextView) converView.findViewById(R.id.myself_text_item);
            viewHolder.myself_zhedie=(ImageView) converView.findViewById(R.id.myself_zhedie_item);
            //将viewHolder与converView绑定
            converView.setTag(viewHolder);
        }else {
            //如果存在converView，取出保存在converView中的viewHolder
            viewHolder=(ViewHolder) converView.getTag();
        }
        myself bean=data.get(position);
        //通过viewHolder找到对应控件，避免每次通过findViewById找控件
        viewHolder.myself_head.setImageResource(bean.icon);
        viewHolder.myself_text.setText(bean.text);
        viewHolder.myself_zhedie.setImageResource(bean.zhedie);

        return converView;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

}
class ViewHolder{
    public ImageView myself_head;
    public TextView myself_text;
    public ImageView myself_zhedie;
}